package com.example.demo.mapper;

import com.example.demo.entity.Order;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface OrderMapper {

    @Select("SELECT * FROM orders")
    List<Order> findAll();

    @Select("SELECT * FROM orders WHERE id = #{id}")
    Order findById(Long id);

    @Insert("INSERT INTO orders(user_id, order_date, total_amount) VALUES(#{userId}, #{orderDate}, #{totalAmount})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insert(Order order);

    @Update("UPDATE orders SET user_id=#{userId}, order_date=#{orderDate}, total_amount=#{totalAmount} WHERE id = #{id}")
    void update(Order order);

    @Delete("DELETE FROM orders WHERE id = #{id}")
    void delete(Long id);
}
